package org.jeecg.modules.solitaire_app.app.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.solitaire_app.app.entity.YsyDrivingTrack;
import org.jeecg.modules.solitaire_app.app.mapper.YsyDrivingTrackMapper;
import org.jeecg.modules.solitaire_app.app.service.IYsyDrivingTrackService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 车辆轨迹订单
 * @Author: jeecg-boot
 * @Date: 2023-11-30
 * @Version: V1.0
 */
@Service
@DS("ysy_db")
public class YsyDrivingTrackServiceImpl extends ServiceImpl<YsyDrivingTrackMapper, YsyDrivingTrack> implements IYsyDrivingTrackService {


    @Override
    public List<YsyDrivingTrack> getYsyDrivingTrackTime(Date startTime, Date endTime, String carNo) {
        return this.baseMapper.getYsyDrivingTrackTime(startTime, endTime, carNo);
    }

    @Override
    public Result<PageInfo<YsyDrivingTrack>> getBigDataDrivingTracks(Map<String, Object> map) {
        Result<PageInfo<YsyDrivingTrack>> result = new Result<>();
        try {
            int pageNo = Integer.parseInt(map.get("pageNo").toString());
            int pageSize = Integer.parseInt(map.get("pageSize").toString());
            PageHelper.startPage(pageNo, pageSize);
            List<YsyDrivingTrack> ysyDrivingTracks = this.baseMapper.getBigDataDrivingTracks(map);
            PageInfo pageInfo = new PageInfo(ysyDrivingTracks);
            result.setSuccess(true);
            result.setCode(200);
            result.setResult(pageInfo);
            return result;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setSuccess(false);
            result.setCode(500);
            result.setMessage("服务器响应失败");
            return result;
        }
    }

    @Override
    public Result<Integer> getBigDataAllOrders() {
        Result result = new Result();
        try {
            Integer count = this.baseMapper.selectCount(Wrappers.<YsyDrivingTrack>lambdaQuery().eq(YsyDrivingTrack::getStatus, 2));
            result.setCode(200);
            result.setResult(count);
            result.setSuccess(true);
            return result;
        }catch (Exception e){
            log.error(e.getMessage(), e);
            result.setSuccess(false);
            result.setCode(500);
            result.setMessage("服务器响应失败");
            return result;
        }
    }
}
